<!--
 * @Author: your name
 * @Date: 2020-05-19 16:58:01
 * @LastEditTime: 2020-06-04 16:56:34
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \mobile_project_200106\mobile_project\src\pages\user\user.vue
--> 

 <template>
  <div class="user">
    <!-- 登录状态 -->
    <template v-if="token">
      <div class="user-poster">
        <p>欢迎,您{{userInfo}}</p>
      </div>
      <van-row class="user-links">
        <van-col span="6">
          <van-icon name="pending-payment" />待付款
        </van-col>
        <van-col span="6">
          <van-icon name="records" />待接单
        </van-col>
        <van-col span="6">
          <van-icon name="tosend" />待发货
        </van-col>
        <van-col span="6">
          <van-icon name="logistics" />已发货
        </van-col>
      </van-row>

      <van-cell-group class="user-group">
        <van-cell icon="records" title="地址管理" is-link to="/address" />
      </van-cell-group>

      <van-cell-group>
        <van-cell icon="points" title="我的积分" is-link />
        <van-cell icon="gold-coin-o" title="我的优惠券" is-link />
        <van-cell icon="gift-o" title="我收到的礼物" is-link />
      </van-cell-group>

      <van-button type="danger" size="large" @click="logout">退出账号</van-button>
    </template>
    
    <!-- 未登录状态 -->

    <template v-else>
      <div class="btn">
        <van-button type="primary" to="/register">用户注册</van-button>
        <van-button type="info" to="/login">用户登录</van-button>
      </div>
    </template>
  

    


    


    <tab-bar></tab-bar>
  </div>
</template>

<script>
import * as api from "@/request/api/user.js"
import { createNamespacedHelpers } from 'vuex'
const { mapState,mapMutations } = createNamespacedHelpers('userModule')
export default {
  data(){
    return{
      // token: localStorage.getItem("token")||""
      userInfo:""
    }
  },
  // created(){
  //   // this.$eventBus.$on("getToken",(res)=>{
  //   //   this.token=res
  //   // })
  // },
  computed:{
    ...mapState(["token"])
  },
  methods:{
    ...mapMutations(["REMOVE_TOKEN"]),
    logout(){//
      this.REMOVE_TOKEN(),//vuex清除密钥
    //   this.token="",//eventBus清除页面密钥
    //  localStorage.removeItem("token")//eventBus清除密钥
      this.$toast.success("退出成功")
    },

    async API_getInfo(){//获取用户信息接口
      let res=await api.getInfo()
      return res
    },

    

    
  },
  async activated(){
      let res=await this.API_getInfo()
      if(res.data.code===1000){
        this.userInfo=res.data.msg
        // console.log(res)
      }
    }
  
};
</script>

<style lang="scss">
@import "@/style/user/user";
</style>